<?php
include("function.php");


function showCountNews($sql){
	$re=mysql_query($sql);
	$count=mysql_num_rows($re);
	return $count;
	}

/*
用来拆分数据库中如：“新浪｜网易” 这样的数据
返回数组
*/
function cf($array){
	if(!empty($array)){
		$val=explode("|",$array);
		return $val;
	}else{
		return false;
		}
	}
	
function showNews(){
	
	if(@$_GET['search']==""){
			$sql="select * from food_caiji_zccw order by news_time desc";
		}else{
			$sql="select * from food_caiji_zccw where area='$_GET[search]' or food like '%$_GET[search]%' or tags like '%$_GET[search]%' or `from` like '%$_GET[search]%' or news_title like '%$_GET[search]%' order by news_time desc";
		}
		$count=showCountNews($sql);
		echo "<div class='news_total oh h'>";
		echo "<h3 class='news_title f22 mb10 fl'>共为您找到了 <span>$count</span> 篇新闻";
		if(@$_GET['city']==1)echo "<span>——\"".@$_GET['search']."\"</span>";
		echo "</h3>";
		echo "<form action='' class='fr'>
							<input type='text' class='news_searchText pl5 pr5' name='search'/>
							<input type='submit' value='搜索' class='news_searchBtn' name='submit'/>
					</form>";
		echo "</div>";
		echo "<hr class=\"news_hr mb40\" />";
		$page=basename($_SERVER['PHP_SELF']); $pagenum=10;
		@$cs="&sear_str=".urlencode(@$sear_str)."&search=".$_GET['search']."&city=".$_GET['city'];
		$sql_1=$sql;
		$sql=page_r($sql,$page,$pagenum,$cs);		
		$query=mysql_query($sql);
		if(@$_GET['ye']==""){
			$i=1;
		}else{
			$i=10*($_GET['ye']-1)+1;
			}		
		while($array=mysql_fetch_array($query)){

			$tags=cf($array['tags']);
			$from=cf($array['from']);
			//var_dump($tags);
			
			echo "<div class='news_record mb30 oh h'>";
			
			echo "<div class='oh mb5 news_recordMain'>";
				//高亮显示 start 周毅添加
				if(@$_GET['search'] != "") {
					$tmp_a = "\\".$_GET[search];
					$news_title = preg_replace("/($tmp_a)/is","<b style=\"color:red\">\\1</b>",$array['news_title']);
				}else {
					$news_title = $array['news_title'];
				}
				//高亮显示 end 
			echo "<p class='news_title fl f16'><a href='$array[news_link]' class='a3' target='_blank'>$i $news_title</a></p>";
			
			echo "<span class='news_date fr'>$array[news_time]</span>";
 	
			echo "</div>";
			
			echo "<div class='news_addition oh'>";
			
			if($array['area']!=""){
				
				echo "<a href='?search=$array[area]' class='news_position fl'>$array[area]</a>";
			}
			
			if($array['food']!=""){
				echo "<a href='?search=$array[food]' class='fl'>$array[food]</a>";
			}
			
			foreach((array)$tags as $val){
				if($val=="")break;
				echo "<a href='?search=$val' class='fl'>$val</a>";
				
				}
			
			foreach((array)$from as $val){
				if($val=="")break;
				echo "<a href='?search=$val' class='news_origin fl'>$val</a>";
				
				}
			
			echo "</div>";
			
			echo "</div>";
			
			$i++;
			}	
		echo "<div style='color:#636363' class='news_flip mb50'>";
		page($sql_1,$page,$pagenum,$cs);
		echo "</div>";
			
	
	}
	
if(@$_POST['submit']){
	echo "<script language=\"javascript\">location.href='?search=$_POST[search]'</script>";
	}
?>